<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head::head('','','/js/bootstrap/page/bootstrap-paginator.js,/js/lims/lims.js')">
</head>
<script th:inline="javascript">
    /*<![CDATA[*/

    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/ 'basepath';
    $(function(){
        intTbleCheckBox();
    });

    function goPage(current){
        var size = $("select[name='size']:eq(0)").val();
        var pageUrl = "?current="+current+"&size="+size;

        var baseUrl = "/lims/orgnazation/orgList";
        var orgName = $("input[name='orgName']:eq(0)").val();
        var orgCode = $("input[name='orgCode']:eq(0)").val();
        var paramUrl = "&orgName="+orgName+"&orgCode="+orgCode;
        var url = baseUrl+pageUrl+paramUrl;
        parent.openMainFrame(url);
    }

    function reFreshTo(){
        var current = $("input[name='current']:eq(0)").val();
        if(current == ""){
            current = [[${page.current}]];
        }
        if(current > [[${page.pages}]]){

            current = [[${page.pages}]];
        }
        goPage(current);
    }

    function resetSearch(){
        $("#search input").val("");
    }

    function addOrg(){
        parent.openModal('组织添加','/lims/orgnazation/addOrgPage','400px','280px');

    }

    function closeModal(){
        parent.closeModal();
    }


    function orgInfo(){
        var checkedIds = getCheckedIds();
        if (checkedIds.length == 0){
            parent.spop({
                template: '请选择',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        if (checkedIds.length != 1){
            parent.spop({
                template: '请选择一条数据进行查看',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        parent.openModal('组织详情',"/lims/orgnazation/findById?orgId="+checkedIds,'350px','220px');
    }




    function updOrg(){
        var checkedIds = getCheckedIds();
        if (checkedIds.length == 0){
            parent.spop({
                template: '请选择',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        if (checkedIds.length != 1){
            parent.spop({
                template: '请选择一条数据进行修改',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        parent.openModal('组织修改','/lims/orgnazation/orgUpdPage?orgId='+checkedIds[0],'400px','280px');
    }
    
    function batchDisable() {
        var checkedIds = getCheckedIds();
        if (checkedIds.length == 0){
            parent.spop({
                template: '请选择',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        confirm("确认禁用此"+checkedIds.length+"条记录?",function(result) {
            if (result){
                $.post({
                    url:basePath+"/lims/orgnazation/batchDisableOrgs",
                    data:{"orgIds":checkedIds.toString()},
                    success:function (data) {
                        if (data){
                            parent.spop({
                                template: '禁用成功',
                                position  : 'top-center',
                                style: 'success',
                                autoclose: 3000
                            });
                            parent.openMainFrame("/lims/orgnazation/orgList");
                        }else{
                            parent.spop({
                                template: '禁用失败',
                                position  : 'top-center',
                                style: 'error',
                                autoclose: 3000
                            });
                        }
                    }
                });

            }
        })

    }

    function batchAble() {
        var checkedIds = getCheckedIds();
        if (checkedIds.length == 0){
            parent.spop({
                template: '请选择',
                position  : 'top-center',
                style: 'error',
                autoclose: 3000
            });
            return false;
        }
        confirm("确认启用此"+checkedIds.length+"条记录?",function(result) {
            if (result){
                $.post({
                    url:basePath+"/lims/orgnazation/batchAbleOrgs",
                    data:{"orgIds":checkedIds.toString()},
                    success:function (data) {
                        if (data){
                            parent.spop({
                                template: '启用成功',
                                position  : 'top-center',
                                style: 'success',
                                autoclose: 3000
                            });
                            parent.openMainFrame("/lims/orgnazation/orgList");
                        }else{
                            parent.spop({
                                template: '启用失败',
                                position  : 'top-center',
                                style: 'error',
                                autoclose: 3000
                            });
                        }
                    }
                });

            }
        })

    }
    /*]]>*/
</script>

<body>
    <div class="container-fluid" style="margin-left: 0px;margin-top: 20px;">
        <div class="row">
            <div class="col-lg-12">
                <form th:id="search" class="form-inline">
                    <div class="input-group mb-3 input-group-sm" style="margin-left: 10px;">
                        <div class="input-group-prepend">
                            <span class="input-group-text">组织名称</span>
                        </div>
                        <input type="text" th:name="orgName" th:value="${orgnazation.orgName}"  autocomplete="off" class="form-control">
                    </div>
                    <div class="input-group mb-3 input-group-sm" style="margin-left: 10px;">
                        <div class="input-group-prepend">
                            <span class="input-group-text">组织编码</span>
                        </div>
                        <input type="text" th:name="orgCode" th:value="${orgnazation.orgCode}" autocomplete="off" class="form-control">
                    </div>
                </form>
                <button type="button" class="btn btn-sm btn-success" th:onclick="'javascript:addOrg()'"><span class="glyphicon glyphicon-plus" th:text="新增"></span></button>
                <button type="button" class="btn btn-sm btn-danger" th:onclick="'javascript:batchDisable()'"><span class="glyphicon glyphicon-remove" th:text="禁用"></span></button>
                <button type="button" class="btn btn-sm btn-danger" th:onclick="'javascript:batchAble()'"><span class="glyphicon glyphicon-ok" th:text="启用"></span></button>
                <button type="button" class="btn btn-sm btn-warning" th:onclick="'javascript:updOrg()'"><span class="glyphicon glyphicon-pencil" th:text="编辑"></span></button>
                <button type="button" class="btn btn-sm btn-success" th:onclick="'javascript:orgInfo()'"><span class="glyphicon glyphicon-eye-open" th:text="详情"></span></button>

                <button type="button" class="btn btn-sm btn-warning float-right" th:onclick="'javascript:resetSearch()'"><span class="glyphicon glyphicon-circle-arrow-left" th:text="重置"></span></button>
                <button type="button" class="btn btn-sm btn-info float-right" th:onclick="'javascript:goPage(1)'"><span class="glyphicon glyphicon-search" th:text="查找"></span></button>
                <table class="table table-hover table-sm">
                    <thead class="thead-dark">
                        <tr>
                            <th>
                                <input type="checkbox" th:id="checkAll" style="width: 17px;height: 17px;margin-left: 11px;padding-top: 30px;">
                            </th>
                            <th>序号</th>
                            <th>上级组织名称</th>
                            <th>组织名称</th>
                            <th>组织编码</th>
                            <th>是否启用</th>
                        </tr>
                    </thead>
                    <tbody>
                        <th:block th:if="${page.records.size() > 0}">
                            <tr th:class="${index.even}?'table-info':'table-secondary'" th:each="orgnazation,index:${page.records}" style="height: 20px;">
                                <td>
                                    <input type="checkbox" name="id" th:value="${orgnazation.orgId}" style="width: 18px;height: 18px;margin-left: 10px;margin-top: 5px;">
                                </td>
                                <td th:text="${(page.current -1)* page.size+index.index+1}">序号</td>
                                <td th:unless="${orgnazation.parent}"></td>
                                <td th:if="${orgnazation.parent}" th:text="${orgnazation.parent.orgName}">上级组织名称</td>
                                <td th:text="${orgnazation.orgName}">组织名称</td>
                                <td th:text="${orgnazation.orgCode}">组织编码</td>
                                <td th:if="${orgnazation.available}">启用中</td>
                                <td th:unless="${orgnazation.available}">未启用</td>
                            </tr>
                        </th:block>
                        <th:block th:if="${page.records.size() eq 0}">
                            <tr th:class="table-info">
                                <td th:colspan="9" th:text="暂无数据" th:align="center"></td>
                            </tr>
                        </th:block>
                    </tbody>

                </table>
                <th:block th:if="${page.records.size() eq 0}">
                    <div style="display: none">
                        <ul class="pagination pagination-sm">
                            <li class="page-item">
                                <select name="size" style="height: 30px;border: 0px;" th:onchange="'javascript:goPage(1)'">
                                    <option value="5" th:selected="${page.size eq 5}?'selected'">5</option>
                                    <option value="10" th:selected="${page.size eq 10}?'selected'">10</option>
                                    <option value="15" th:selected="${page.size eq 15}?'selected'">15</option>
                                </select>
                            </li>


                            <li class="page-item"><input type="text" th:name="current"  style="width: 50px;height: 30px;border: 0px;"/></li>
                        </ul>

                    </div>

                </th:block>
                <th:block th:unless="${page.records.size() eq 0}">
                    <ul class="pagination pagination-sm">
                        <li th:if="${page.current == page.pages}" class="page-item disabled"><a class="page-link" th:text="'显示'+${(page.current - 1)*page.size +1}+'-'+${page.total}+'/'+${page.getTotal()}+''" href="#">共6页</a></li>
                        <li th:unless="${page.current == page.pages}" class="page-item disabled"><a class="page-link" th:text="'显示'+${(page.current - 1)*page.size +1}+'-'+${page.current * page.size}+'/'+${page.total}+''" href="#">共6页</a></li>
                        <li class="page-item">
                            <select name="size" style="height: 30px;border: 0px;" th:onchange="'javascript:goPage(1)'">
                                <option value="5" th:selected="${page.size eq 5}?'selected'">5</option>
                                <option value="10" th:selected="${page.size eq 10}?'selected'">10</option>
                                <option value="15" th:selected="${page.size eq 15}?'selected'">15</option>
                            </select>
                        </li>
                        <!--总页数小于7时-->
                        <th:block th:if="${page.pages gt 0 && page.pages lt 7 }">
                            <li th:if="${page.current eq 1}" class="page-item disabled"><a class="page-link" href="#">上一页</a></li>
                            <li th:if="${page.current gt 1}" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${page.current - 1}+'\')'" href="#">上一页</a></li>
                            <li th:each="index:${#numbers.sequence(1,page.pages)}" th:classappend="${page.current eq index}?'active'" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${index}+'\')'" th:text="${index}" href="#"></a></li>
                            <li th:if="${page.current lt page.pages}" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${page.current + 1}+'\')'" href="#">下一页</a></li>
                            <li th:if="${page.current eq page.pages}" class="page-item disabled"><a class="page-link" href="#">下一页</a></li>
                        </th:block>
                        <th:block th:if="${page.pages gt 7}">
                            <li class="page-item" th:classappend="${page.current eq 1}?'active'"><a class="page-link" th:onclick="'javascript:goPage(1)'" href="#">首页</a></li>
                            <li th:if="${page.current eq 1}" class="page-item disabled"><a class="page-link" href="#">上一页</a></li>
                            <li th:if="${page.current gt 1}" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${page.current - 1}+'\')'" href="#">上一页</a></li>
                            <th:block th:if="${page.current < 4}">
                                <li th:if="${page.current lt 4}" th:each="index:${#numbers.sequence(1,3)}" th:classappend="${page.current eq index}?'active'" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${index}+'\')'"  th:text="${index}" href="#"></a></li>
                                <li th:if="${page.current lt 4}" class="page-item"><a class="page-link" href="#" th:onclick="'javascript:goPage(4)'">...</a></li>
                            </th:block>

                            <th:block th:if="${page.current > 3 && page.pages - page.current gt 2}">
                                <li class="page-item"><a class="page-link" href="#" th:onclick="'javascript:goPage(\''+${page.current - 3}+'\')'">...</a></li>
                                <li th:each="index:${#numbers.sequence(page.current,page.current+2)}" th:classappend="${page.current eq index}?'active'" class="page-item"><a class="page-link" th:onclick="'javascript:goPage(\''+${index}+'\')'"  th:text="${index}" href="#"></a></li>
                                <li class="page-item"><a class="page-link" href="#" th:onclick="'javascript:goPage(\''+${page.current + 3}+'\')'">...</a></li>
                            </th:block>




                            <th:block th:if="${page.pages - page.current lt 3}">
                                <li class="page-item"><a class="page-link" href="#" th:onclick="'javascript:goPage(\''+${page.current - 3}+'\')'">...</a></li>
                                <li th:each="index:${#numbers.sequence(page.pages - 2,page.pages)}" th:classappend="${page.current eq index}?'active'" class="page-item"><a class="page-link" th:text="${index}" href="#" th:onclick="'javascript:goPage(\''+${index}+'\')'"></a></li>
                            </th:block>
                            <li th:if="${page.current lt page.pages}" class="page-item"><a class="page-link" href="#" th:onclick="'javascript:goPage(\''+${page.current + 1}+'\')'">下一页</a></li>
                            <li th:if="${page.current eq page.pages}" class="page-item disabled"><a class="page-link" href="#">下一页</a></li>
                            <li class="page-item" th:classappend="${page.current eq page.pages}?'active'"><a class="page-link" href="#" th:onclick="'javascript:goPage('+${page.pages}+')'">尾页</a></li>
                        </th:block>
                        <li class="page-item"><input type="text" th:name="current"  style="width: 50px;height: 30px;border: 0px;"/></li>
                        <li class="page-item"><a class="page-link" href="#" th:onclick="'javascript:reFreshTo()'">跳转</a></li>
                        <li class="page-item disabled"><a class="page-link" th:text="'共'+${page.pages}+'页'" href="#">共6页</a></li>
                    </ul>
                </th:block>
            </div>
        </div>
    </div>
</body>
</html>